<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%@include file="../common/header.jsp"%><title>用户地址管理</title>
</head>
<script>
$(function() {
	$('#name').val("");
	$('#province').val("");
	$('#city').val("");
	$('#area').val("");
	$('#detail').val("");
	$('#postcode').val("");
	$('#phone').val("");
});
function submit_address()
{

	if($('#name').val()=="")
	{
		$.messager.alert("消息提醒", "收件人姓名不能为空！", "warning");
		return;
	}
	if($('#province').val()=="")
	{
		$.messager.alert("消息提醒", "省份不能为空！", "warning");
		return;
	}
	if($('#city').val()=="" && $('#area').val()=="" )
	{
		$.messager.alert("消息提醒", "市/县和区/县至少填一个！", "warning");
		return;
	}
	if($('#detail').val()=="")
	{
		$.messager.alert("消息提醒", "收货地址不能为空！", "warning");
		return;
	}
	if($('#postcode').val()=="")
	{
		$.messager.alert("消息提醒", "邮编不能为空！", "warning");
		return;
	}
	if($('#phone').val()=="")
	{
		$.messager.alert("消息提醒", "收件人电话不能为空！", "warning");
		return;
	}
	
	var data = $("#address_form").serialize();
	$.ajax({
		type: "post",
		url: "/TeaShop/home/account/add_address",
		data: data, 
		dataType: "json", //返回数据类型
		success: function(result){
			if(result.type == 'success'){
				$.messager.alert("消息提醒", result.msg, "info",function () {window.location.href = "/TeaShop/home/account/address";});
			}
			else{
				$.messager.alert("消息提醒", result.msg, "warning");
			}
			
		}
		
	});
}

function del_address(i)
{
	if(i==""||i==null)
	{
		$.messager.alert("消息提醒", "没有地址可以删除！", "warning");
		return;
	}
	
	$.messager.confirm("消息提醒", "你确定要删除这个地址吗",function (data) {
        if (data) {
        	
        	$.ajax({
        		type: "post",
        		url: "/TeaShop/home/account/del_address",
        		data: {id:i}, 
        		dataType: "json", //返回数据类型
        		success: function(result){
        			if(result.type == 'success'){
        				$.messager.alert("消息提醒", result.msg, "info", function () {window.location.href = "/TeaShop/home/account/address";});
        			}
        			else{
        				$.messager.alert("消息提醒", result.msg, "warning");
        				
        			}
        			
        		}
        		
        	});
        	
        }
        else {
        	
        	return;
        	
        }
    });
	
}

</script>
<body>
<%@include file="../common/common_top.jsp"%>
<!--导航栏样式-->
<div id="Menu" class="clearfix">
<div class="Menu_style">
  <div id="allSortOuterbox" class="display">
    <div class="Category"><a href="#" class="Menu_img"><em></em></a></div>
    <div class="hd_allsort_out_box_new">
	 <!--左侧栏目开始-->
	 <div class="Menu_list">	
	    <div class="menu_title">茶叶品种</div>
	    	<c:forEach items="${teaCategoryList}" var="teaCategory">
				<a class="nav_on" id="mynav"  href="${teaCategory.href}">${teaCategory.name}</a>
			</c:forEach>
	 </div>	
    <div class="Menu_list">	
	    <div class="menu_title">茶叶价格</div>
        <a href="/TeaShop/home/product/list?price=1&flag2=1">100以下</a><a href="/TeaShop/home/product/list?price=2&flag2=1">100-200</a>
        <a href="/TeaShop/home/product/list?price=3&flag2=1">200-400</a><a href="/TeaShop/home/product/list?price=4&flag2=1">400-600</a>
        <a href="/TeaShop/home/product/list?price=5&flag2=1">600-900</a><a href="/TeaShop/home/product/list?price=6&flag2=1">1000以上</a>
	</div>	
     <div class="Menu_list">	
	    <div class="menu_title">推荐茶叶</div>
        <ul class="recommend">
       		<c:set var="count" value="0"></c:set>
            <c:forEach items="${teaListByActionId}" var="tea">
             		<!-- 只允许显示2个 -->
             		<c:if test="${count < 2}">
        			 	<li><a href="${tea.href}" title="${tea.name}">${tea.name}</a></li>
              		  	<c:set var="count" value="${count+1}"></c:set>
       			</c:if>
       		</c:forEach>
        </ul>
	</div>	
	</div>		
	</div>
     <div class="Navigation" id="Navigation">
		 <ul class="Navigation_name">
			<li><a class="nav_on" id="mynav"  href="/TeaShop/home/system/index"><span>首页</span></a></li>
			<c:forEach items="${teaCategoryList}" var="teaCategory">
				<li><a class="nav_on" id="mynav"  href="${teaCategory.href}"><span>${teaCategory.name}</span></a></li>
			</c:forEach>
		 </ul>			 
	</div>
	
    <!--购物车-->	
    
     <div class="hd_Shopping_list" id="Shopping_list">
   <div class="s_cart"><em></em><a href="#">我的购物车</a> <i class="ci-right">&gt;</i><i class="ci-count" id="shopping-amount">${cartTotal}</i></div>
   <div class="dorpdown-layer">
    <div class="spacer"></div>
	 <!--<div class="prompt"></div><div class="nogoods"><b></b>购物车中还没有商品，赶紧选购吧！</div>-->
	 <ul class="p_s_list">	   
		
	 	 <c:set var="totalPrice" value="0"></c:set>
 		 <c:forEach items="${cartList}" var="cart" varStatus="vs">
			  <li>
			    <div class="img"><img src="${cart.tea.photo}" style="width:40px;height:40px;"></div>
			    <div class="content">
			      <p><a href="${cart.tea.href}">${cart.tea.name}</a></p><p>${cart.tea.info}</p>
			    </div>
				<div class="Operations">
				<p class="Price">￥${cart.tea.new_price}</p>
				<p>数量：${cart.num}</p></div>
			  </li>
			   <c:set var="totalPrice" value="${totalPrice+cart.tea.new_price*cart.num}"></c:set>
		 </c:forEach>
	</ul>		
	 <div class="Shopping_style">
	  <div class="p-total">共<b>${cartTotal}</b>件商品　共计<strong>￥ ${totalPrice}</strong></div>
	  <a href="/TeaShop/home/shopping/cart" title="去购物车结算" id="btn-payforgoods" class="Shopping">去购物车结算</a>
	 </div>	
   </div>	
  </div>
</div>
</div>
<!--用户中心(地址管理界面)-->
<div class="user_style clearfix" id="user">
<div class="user_title"><em></em>用户中心</div>
 <div class="clearfix user" >
   <!--左侧菜单栏样式-->
     <div class="user_left">
      <div class="user_info">
       <div class="Head_portrait"><img src="${account.photo}"  width="80px" height="80px"/><!--头像区域--></div>
       <div class="user_name">${account.username}<a href="/TeaShop/home/account/info">[个人资料]</a></div>
      </div>
      <ul class="Section">
       <li><a href="/TeaShop/home/account/info"><em></em><span>个人信息</span></a></li>
       <li><a href="/TeaShop/home/account/password"><em></em><span>修改密码</span></a></li>
       <li><a href="/TeaShop/home/account/order?page=1&rows=7"><em></em><span>我的订单</span></a></li>
       <li><a href="/TeaShop/home/account/comment?page=1&rows=4"><em></em><span>我的评论</span></a></li>
       <li><a href="/TeaShop/home/account/collect?page=1&rows=4&accountId=${account.id}"><em></em><span>我的收藏</span></a></li>
       <li><a href="/TeaShop/home/account/address"><em></em><span>收货地址管理</span></a></li>
      </ul>
    </div>
  
    <!--右侧内容样式-->
    <div class="right_style r_user_style">
      <div class="user_Borders">
       <div class="title_name">
        <span class="name">地址管理</span>
       </div>
       <div class="about_user_info">
         <form id="address_form" method="post" >   
       <div class="user_layout">
         <ul>
          <li class="li"><label class="user_title_name">收件人姓名：</label><input name="name" id="name" type="text" class="add_text"><i>*</i></li>
          
          <li class="li">
          
          <label>省份：</label><input name="province" id="province" type="text" style="width:100px;height:34px;">
          <label>市/县 ：</label><input name="city" id="city" type="text" style="width:100px;height:34px;">
          <label>区/县 ：</label><input name="area" id="area" type="text" style="width:100px;height:34px;">
            <i>*</i>
		 
        </li >
          <li class="li"><label class="user_title_name">收货地址：</label><input name="detail" id="detail" type="text" class="add_text"><i>*</i></li>
          <li class="li"><label class="user_title_name">邮&nbsp;&nbsp;&nbsp;&nbsp;编：</label><input name="postcode" id="postcode" type="text" class="add_text"><i>*</i></li>
          <li class="li"><label class="user_title_name">收件人手机号：</label><input name="phone" id="phone" type="text" class="add_text" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')"><i>*</i></li>
         </ul>
         <div class="operating_btn">
         	<input name="name" type="button" value="添加"  onclick="submit_address();" style="border:0px; background:url(../../resources/home/images/Button_img.png) no-repeat; height:37px; 
				text-align:center;width:270px; font-size:18px; color:#FFF;cursor:pointer"></div>
         </div>
          </form>       
       </div>
       <!--地址列表-->
       <div class="Address_List">
        <div class="title_name"><span class="name">用户地址列表</span></div>
        <div class="list">
         <table>
         <thead>
          <td class="list_name_title0">收件人姓名</td>
          <td class="list_name_title1">地区</td>
          <td class="list_name_title2">邮编</td>
          <td class="list_name_title3">电话</td>
          <td class="list_name_title4">收货地址</td>
          <td class="list_name_title5">操作</td>
         </thead>        
        
          
          	 <tr>
				<td>${address.name}</td>
          		<td>${address.province}${address.city}${address.area}</td>
          		<td>${address.postcode}</td>
          		<td>${address.phone}</td>
          		<td>${address.detail}</td>
          		<td><a href="javascript:void(0);" onclick='del_address("${address.id}");'>删除</a></td>
          	  </tr>
          		
          
         </table>
        </div>
       </div>
      </div>
   </div>
 </div>
</div>
<%@include file="../common/footer.jsp"%>
</body>
</html>
